package com.bnzj.cloud.business.core.service;

import com.bnzj.cloud.business.core.persistence.entity.SysRole;
import com.bnzj.cloud.business.core.persistence.repository.SysRoleRepository;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service
public class SysRoleService extends BaseService<SysRoleRepository, SysRole, Long> {


    public Set<SysRole> eagerlyFindAll() {
        return repository.eagerlyFindAll();
    }

    /**
     * @return
     */
    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "select r.*";
        String whereSQL = " from bnz_sys_role r where 1 = 1 ";
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, SysRole.class);
        return queryBean;
    }

    public SysRole findByCode(String code) {
        return repository.findByCode(code);
    }

    public List<String> findAllCode() {
        return repository.findAllCode();
    }

    /**
     * @param username
     * @return
     */
    public List<String> getAllRoleCodeByAccount(String username) {
        return repository.getAllRoleCodeByAccount(username);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateEnabled(Short type, Long id) {
        repository.updateEnabled(type, id);
    }


}
